package com.Gwo.org.service.impl;

import com.Gwo.basic.utils.PageList;
import com.Gwo.org.domain.Employee;
import com.Gwo.org.mapper.EmployeeMapper;
import com.Gwo.org.query.EmployeeQuery;
import com.Gwo.org.service.IDeptService;
import com.Gwo.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper empMapper;

    @Override
    public Employee findById(Long id) {
        return empMapper.findById(id);
    }

    @Override
    public List<Employee> findAll() {
        return empMapper.findAll();
    }

    @Override
    @Transactional
    public void add(Employee employee) {
        empMapper.add(employee);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        empMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        empMapper.update(employee);
    }

    @Override
    public PageList<Employee> queryByPage(EmployeeQuery query) {
        if (!StringUtils.isEmpty(query.getKeyword())){
            query.setKeyword(query.getKeyword().trim());
        }
        // 查询数量
        Integer totals = empMapper.queryByCount(query);
        // 查询数据
        List<Employee> employees = empMapper.queryByPage(query);
        if(employees.size()==0){
            return null;
        }
        return new PageList<Employee>(totals,employees);
    }

    @Override
    @Transactional
    public void batchDelete(List<Long> ids) {
        empMapper.batchDelete(ids);
    }


}
